package com.design.model;

/**
 * def
 *
 * @author lw
 * @date 2023/12/4 15:10
 **/
public class InterpreterPatternExample {

    public static void main(String[] args) {
        // 构建表达式：2 + (3 - 1)
        Expression expression = new AddExpression(
                new NumberExpression(2),
                new SubtractExpression(
                        new NumberExpression(3),
                        new NumberExpression(1)
                )
        );

        // 解释并计算表达式的值
        int result = expression.interpret();
        System.out.println("Result: " + result); // 输出: Result: 4
    }
}
